home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr22 / dtsav3.zip / DTSAV3.ASM next >
Assembly Source File  |  1993-05-01  |  4KB  |  147 lines

  1.     title    DTSAV3 - write a .COM program to set current date and time
  2.  
  3. ;
  4. ;    Written by Jim Knutson, 13 Nov 1984.
  5. ;    v2.0 : Vastly hacked and updated by David Kirschbaum, Toad Hall
  6. ;        kirsch@braggvax.ARPA, 20 Oct 86.
  7. ;    v3.0 : Changed again to produce a .COM program (faster than .BAT,
  8. ;        running a .COM is cleaner than nesting .BAT files, etc.)
  9. ;
  10. ;    DTSAV allows a programmer the ability of a faster boot when
  11. ;    having to reboot a system by writing a file called DT.COM
  12. ;    which contains commands to set the current date and time.
  13. ;    If this is run immediately before executing a program that
  14. ;    is being debugged, then DT.COM may be used to reset the date
  15. ;    and time if the system hangs and must be rebooted.  DT.COM
  16. ;    may also be used to speed up a boot during the same day 
  17. ;    because only the time would have to be corrected.
  18. ;
  19. ;    This particular version writes the program DT.COM to C: drive,
  20. ;    root directory (where it's accessible for AUTOEXEC.BAT).
  21. ;    Change the variable DTA below for your desired target drive\directory.
  22.  
  23. ;    To create DTSAV, use:
  24. ;
  25. ;        MASM DTSAV;
  26. ;        LINK DTSAV;
  27. ;        EXE2BIN DTSAV
  28. ;        REN DTSAV.BIN DTSAV.COM
  29. ;    (or use the public domain utility EXE2COM and change the .EXE file
  30. ;    directly to a .COM file, with this command:
  31. ;        EXE2COM DTSAV 
  32. ;    )
  33. ;        DEL DTSAV.OBJ
  34. ;        DEL DTSAV.EXE
  35. ;
  36. ;Toad Hall Note:
  37. ; Updates include:
  38. ;    Changing to file handles throughout.
  39. ;    Dumping all the old FCB-related stuff.
  40. ;    New code to Asciify date and time numbers and stuff them into
  41. ;      a clean little preformatted buffer.
  42.  
  43. CrLf    equ    0A0DH        ; Cr/Lf in lo/hi order
  44.  
  45. CodeSeg    segment    para
  46.     assume    CS:CodeSeg, ss:CodeSeg, DS:CodeSeg, ES:CodeSeg
  47.     org    100H
  48.  
  49. DtSav:    jmp    Start
  50.  
  51. ErrorStr db    'DTSAV failed.',0DH,0AH,'$'
  52.  
  53. ;This is the code fragment that'll be modified with the current date and time,
  54. ;and then written out to file as DT.COM.
  55.  
  56. CodeFrag:
  57.     mov    ah,2AH            ;set date
  58.     mov    cx,0000H        ;year (self-modifying)
  59. year    equ    $-2            ;point to the integer
  60.     mov    dx,0000H        ;the month and day (self-modifying)
  61. mon_day    equ    $-2            ;point to the integer
  62.     mov    ah,2BH            ;set date
  63.     int    21H
  64.     mov    cx,0000H        ;hours and minutes
  65. hr_min    equ    $-2            ;point to the integer
  66.     mov    dx,0000H        ;seconds and hundredths
  67. seconds    equ    $-2            ;point to the integer
  68.     mov    ah,2DH            ;set time
  69.     int    21H
  70. Exit:
  71.     mov    ax,4C00H        ;terminate process
  72.     int    21H            ;done
  73.  
  74. CODELENGTH equ    $ - CodeFrag + 1    ;how much to write to DT.COM
  75.  
  76.  
  77. DTA    db    'C:\DT.COM',0        ;force to C drive, root directory
  78.  
  79. ;If you don't want DT.COM written to C:\, change as you wish.
  80. ;This example writes DT.COM to the current drive/subdirectory:
  81. ;DTA    db    'DT.COM',0        ; filename as AsciiZ string
  82.  
  83. handle    dw    ?            ;file handle
  84.  
  85. Start:
  86.     mov    ax,CS            ;This is NOT really necessary...
  87.     mov    DS,ax            ;DS=CS
  88.     mov    ES,ax            ;ES=CS
  89.  
  90.     mov    ah,41H            ;- delete any version of DT.COM
  91.     mov    dx,offset DTA        ;DS:dx points to DTA w/file name
  92.     int    21H            ;don't care if it fails
  93.  
  94.     mov    ah,3CH            ;- create entry for DT.COM
  95.                     ;DTA pointer still in DS:dx
  96.     xor    cx,cx            ;read/write attrib
  97.     int    21H
  98.     jb    File_error        ; failed
  99.  
  100.     mov    handle,ax        ;remember the handle
  101.  
  102.     call    FixCode            ; get date/time, stuff in code
  103.  
  104.     call    CloseF            ; close the file
  105.     jnb    Exit            ; and terminate process if no error
  106.  
  107. File_error:
  108.     mov    dx,offset ErrorStr    ;File error msg
  109.     mov    ah,9            ;display string
  110.     int    21H            ;DOS
  111.     mov    ax,4C02H        ;error=critical device error
  112.     int    21H            ;terminate process
  113. ;
  114. ;
  115. FixCode    proc    near
  116.     mov    ah,2AH            ; get date
  117.     int    21H
  118. ;AL=day of week
  119. ;CX=year
  120. ;DX=month day
  121.     mov    word ptr year,cx    ;stuff in our little code fragment
  122.     mov    word ptr mon_day,dx    ;month/day also
  123.  
  124.     mov    ah,2CH            ; get time
  125.     int    21H
  126. ;CX=hours minutes
  127. ;DX=seconds deciseconds
  128.     mov    word ptr hr_min,cx    ;stuff in our little code fragment
  129.     mov    word ptr seconds,dx
  130.     ret
  131. FixCode    endp
  132.  
  133. CloseF    proc    near
  134.     mov    bx,handle        ;get handle back
  135.     mov    cx,CODELENGTH        ;length of our subprogram code
  136.     mov    dx,offset CodeFrag    ;DS:dx pointer to our subprogram
  137.     mov    ah,40H            ;write to file or device
  138.     int    21H            ;write out the block
  139.     jb    CloseX            ;error, return with carry set
  140.     mov    ah,3EH            ;close file handle (still in bx)
  141.     int    21H            ;close up file
  142. CloseX:    ret
  143. CloseF    endp
  144.  
  145. CodeSeg    ends
  146.     end    DtSav
  147.